package com.tron.dobest.java.trontime;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.temporal.ChronoField;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

/**
 * @description 时间
 * @auther TRON
 * @create 2020-02-14
 */
public class Start {
    public static void main(String[] args) {
        /**
         *
         * CST可视为美国、澳大利亚、古巴或中国的标准时间。
         *
         * UTC协调世界时，又称世界统一时间、世界标准时间、国际协调时间。
         * 中国大陆UTC的时差均为+8，也就是UTC+8
         *
         * GMT格林尼治
         * 时区：全球一共有24时区，英国格林尼治是0时区，北京是东八区。也就是说格林尼治凌晨1点，北京就是早上9点
         * 0时区用GMT+0表示  北京时间用GMT+8表示
         *
         * 时刻&纪元时：所有计算机系统内部都用一个整数表示时刻，这个整数是距离格林尼治时间 1970-01-01 00:00:00:00 的毫秒数（纪元时）。
         *
         * 年历：年历区分每月的天数
         *
         * 如果
         * show variables like '%time_zone%'
         * UTC
         * SYSTEM
         *
         * 需要
         * [mysqld]
         * default-time-zone = '+08:00'
         *
         *
         */


        Date date = new Date();
        System.out.println(date);

        /**
         * TimeZone 表示时区
         */
        //id="Asia/Shanghai",offset=28800000
        TimeZone aDefault = TimeZone.getDefault();
        System.out.println(aDefault);
        TimeZone timeZone = TimeZone.getTimeZone("Asia/Shanghai");
        System.out.println(timeZone);
        //map.put("CTT", "Asia/Shanghai");
        TimeZone asia = TimeZone.getTimeZone("CTT");
        //id="CTT",offset=28800000,
        System.out.println(asia);

        /**
         * local 表示国家
         */
        Locale aLocale = Locale.getDefault();
        //zh_CN
        System.out.println(aLocale);
        //"zh" (Chinese) zh-cn 就是代表:zh-CN 华 - 中国
        Locale zhCn = Locale.forLanguageTag("zh-CN");
        //zh_CN
        System.out.println(zhCn);

        System.out.println("--------------------------------------------");

        LocalDateTime now = LocalDateTime.now();

        /**
         * TemporalField时域接口
         *     ---ChronoField
         */
        int i = now.get(ChronoField.ALIGNED_WEEK_OF_MONTH);
        System.out.println(String.format("当月第%1$d周",i));
        int i1 = now.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH);
        System.out.println(String.format("月中周几%1$d",i1));
        int i2 = now.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR);
        System.out.println(String.format("年中周几%1$d",i2));
        int i3 = now.get(ChronoField.ALIGNED_WEEK_OF_YEAR);
        System.out.println(String.format("年中第%1$d周",i3));
        int i4 = now.get(ChronoField.AMPM_OF_DAY);
        System.out.println("时间段，上午0，下午1，#"+i4);
        int i5 = now.get(ChronoField.CLOCK_HOUR_OF_AMPM);
        System.out.println("时钟时间12时="+i5);
        int i6 = now.get(ChronoField.CLOCK_HOUR_OF_DAY);
        System.out.println("时钟时间24时="+i6);
        int i7 = now.get(ChronoField.DAY_OF_MONTH);
        System.out.println("几号="+i7);
        int i8 = now.get(ChronoField.DAY_OF_WEEK);
        System.out.println("周几="+i8);
        int i9 = now.get(ChronoField.DAY_OF_YEAR);
        System.out.println("年中第几天="+i9);
        long i10 = now.getLong(ChronoField.EPOCH_DAY);
        System.out.println("纪元天="+i10);
        int i11 = now.get(ChronoField.HOUR_OF_AMPM);
        System.out.println("时钟时间12时="+i11);
        int i12 = now.get(ChronoField.HOUR_OF_DAY);
        System.out.println("时钟时间24时="+i12);
        int i13 = now.get(ChronoField.MICRO_OF_SECOND);
        System.out.println(i13);
        int i14 = now.get(ChronoField.MILLI_OF_DAY);
        System.out.println(i14);
        int i15 = now.get(ChronoField.MINUTE_OF_HOUR);
        System.out.println("分钟="+i15);


        Instant instant = now.toInstant(ZoneOffset.of("+8"));
        System.out.println(instant.getEpochSecond());

        boolean before = now.isBefore(LocalDateTime.of(2020, 3, 3, 19, 9, 20));
        System.out.println("判断是否在3月3日之前："+before);

        boolean after = now.isAfter(LocalDateTime.of(2020, 3, 3, 19, 9, 20));
        System.out.println("判断是否在3月3日之后:"+after);

        int i16 = now.compareTo(LocalDateTime.of(2020, 3, 3, 19, 9, 20));
        System.out.println("大于3月3日返回："+i16);


    }
}
